package it.unibo.refolding.pico.testing;

import it.unibo.refolding.common.MyRuntimeException;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.io.IOUtils;


public class TestResources {

    public static final byte[] jpkSampleFileContent1 = loadResource("jpk/VeecodoubleSidedfunzGB1a-12567.jpk-force");
    public static final byte[] csvSampleFileContent1 = loadResource(
        "csv/Modules_8_T_298.15_k_0.06_v_tau_1.4047824384323529551e-08_Blackhole_native_peptide_bonds_Iteration_1.csv");
    public static final byte[] csvSampleFileContent2 = loadResource(
        "csv/Modules_8_T_298.15_k_0.06_v_4.36e-06_tau_0.0281751005402_Blackhole_native_peptide_bonds_Iteration_0.csv");
    public static final byte[] csvSampleFileContent3 = loadResource(
        "csv/Modules_8_T_298.15_k_0.06_v_4.36e-06_tau_0.0032219780698_Blackhole_native_peptide_bonds_Iteration_9.csv");
    public static final byte[] csvSampleFileContent4 = loadResource(
        "csv/Modules_8_T_298.15_k_0.06_v_1e-09_tau_0.0005_Blackhole_length_units_Iteration_0.csv");

  public static final byte[] ibwVersion5 = loadResource("igor/version5.ibw");
  public static final byte[] ibwVersion2 = loadResource("igor/version2.ibw");
  public static final byte[] mfpDeflection0 = loadResource("mfp/2013-01-18deflection30000.ibw");
  public static final byte[] mfpPiezo0 = loadResource("mfp/2013-01-18LVDT30000.ibw");
  
  public static final byte[] mfpDeflection1 = loadResource("mfp/2013-01-23deflection151000.ibw");
  public static final byte[] mfpPiezo1 = loadResource("mfp/2013-01-23LVDT151000.ibw");
  
  public static final byte[] away_15s_30pPerSDwellDefl00 = loadResource("mfp/away_15s_30pPerSDwellDefl00.ibw");
  public static final byte[] away_15s_30pPerSDwellLVDT00 = loadResource("mfp/away_15s_30pPerSDwellLVDT00.ibw");
  /**
   * WAVES away_15s_30pPerSLVDT0000, Time:1:25:00 AM.
   */
  public static final byte[] away_15s_30pPerSLVDT0000 = loadResource("mfp/away_15s_30pPerSLVDT0000.ibw");
  /**
   * WAVES away_15s_30pPerSZPosition0000, Time:1:24:59 AM.
   * Very similar, but not identical, to away_15s_30pPerSLVDT0000.
   */
  public static final byte[] away_15s_30pPerSZPosition00 = loadResource("mfp/away_15s_30pPerSZPosition00.ibw");
  /*
   * The longest filename: 34 characters.
   */
  public static final byte[] away_15s_30pPerSdeflection0000 = loadResource("mfp/away_15s_30pPerSdeflection0000.ibw");
  public static final byte[] away_3s_30pPerSLVDT0001 = loadResource("mfp/away_3s_30pPerSLVDT0001.ibw");
  public static final byte[] away_3s_30pPerSdeflection0001 = loadResource("mfp/away_3s_30pPerSdeflection0001.ibw");
  public static final byte[] both_12s_30pPerSAfterDefl00 = loadResource("mfp/both_12s_30pPerSAfterDefl00.ibw");
  public static final byte[] both_12s_30pPerSAfterLVDT00 = loadResource("mfp/both_12s_30pPerSAfterLVDT00.ibw");
  public static final byte[] both_12s_30pPerSDwellDefl00 = loadResource("mfp/both_12s_30pPerSDwellDefl00.ibw");
  public static final byte[] both_12s_30pPerSDwellLVDT00 = loadResource("mfp/both_12s_30pPerSDwellLVDT00.ibw");
  public static final byte[] both_12s_30pPerSLVDT0000 = loadResource("mfp/both_12s_30pPerSLVDT0000.ibw");
  public static final byte[] both_12s_30pPerSZPosition00 = loadResource("mfp/both_12s_30pPerSZPosition00.ibw");
  public static final byte[] both_12s_30pPerSdeflection0000 = loadResource("mfp/both_12s_30pPerSdeflection0000.ibw");
  /*
   * Only dwell_noneLVDT0000 is version 2.
   */
  public static final byte[] dwell_noneLVDT0000 = loadResource("mfp/dwell_noneLVDT0000.ibw");
  public static final byte[] dwell_nonedeflection0000 = loadResource("mfp/dwell_nonedeflection0000.ibw");
  public static final byte[] towar_12s_30pPerSDwellDefl0 = loadResource("mfp/towar_12s_30pPerSDwellDefl0.ibw");
  public static final byte[] towar_12s_30pPerSDwellLVDT0 = loadResource("mfp/towar_12s_30pPerSDwellLVDT0.ibw");
  public static final byte[] towar_12s_30pPerSLVDT0000 = loadResource("mfp/towar_12s_30pPerSLVDT0000.ibw");
  public static final byte[] towar_12s_30pPerSZPosition0 = loadResource("mfp/towar_12s_30pPerSZPosition0.ibw");
  public static final byte[] towar_12s_30pPerSdeflection0000 = loadResource("mfp/towar_12s_30pPerSdeflection0000.ibw");
  public static final byte[] towar_8s_30pPerSLVDT0000 = loadResource("mfp/towar_8s_30pPerSLVDT0000.ibw");
  public static final byte[] towar_8s_30pPerSdeflection0000 = loadResource("mfp/towar_8s_30pPerSdeflection0000.ibw");

  public static final byte[] nanoscope5 = loadResource("nanoscope5_01281819.092");
  public static final byte[] nanoscope5FivePeaks = loadResource("nanoscope5_01301721.242");
  public static final byte[] nanoscope5ManyPeaks = loadResource("nanoscope5_01301742.260");
  public static final byte[] nanoscope5HighDetachment = loadResource("nanoscope5_02051815.016");
  
	public static final byte[] sampleFileContent1 = loadResource("20090327a.111.pico");
	public static final byte[] sampleFileContent2 = loadResource("08181023.028.pico");
	public static final byte[] sampleFileContent3 = loadResource("misurata.pico");
	public static final byte[] sampleFileContent4 = loadResource("approach_retraction_sample.pico");
	public static final byte[] sampleFileContent5 = loadResource("002211948.010.pico");
	
	public static final byte[][] mostlyEmpty = {
			loadResource("mostly_empty/12161814.003"),
			loadResource("mostly_empty/12170107.022"),
			loadResource("mostly_empty/12170527.010"),
			loadResource("mostly_empty/12171048.027"),
			loadResource("mostly_empty/12171429.017"),
	};
	
	public static final byte[] sampleStripChartFileContent() {return loadResource("stripchart.pico");}

	public static final byte[] fetchMoleculeLike1() {
		return loadResource("11271015.001.pico");
	}

	public static final byte[] fetchMoleculeLike2() {
		return loadResource("11271018.001.pico");
	}

	public static final byte[] fetchMoleculeLike3() {
		return loadResource("11271024.004.pico");
	}

	public static final byte[] fetchMoleculeLike4() {
		return loadResource("11271012.001.pico");
	}

	public static final byte[] refolding1() {
		return loadResource("11270924.002.pico");
	}

	public static final byte[] refolding2() {
		return loadResource("11270940.005.pico");
	}

	public static byte[] loadResource(String filename) {
		InputStream stream = TestResources.class.getResourceAsStream("/it/unibo/refolding/pico/" + filename);
		if (stream == null) {
			return null;
		} else {
			try {
				return IOUtils.toByteArray(stream);
			} catch (IOException e) {
				throw new MyRuntimeException(e.getMessage(), e);
			}
		}
	}

	public static byte[] sampleStripChartFileContent1() {
		return loadResource("breakAway_2_04272221.001.pico");
	}

	public static byte[] sampleStripChartFileContent2() {
		return loadResource("stripchart_500nm_10000Hz_loop0.pico");
	}
	
	public static byte[] sampleStripChartFileContent3() {
		return loadResource("stripchart_110nm_5000Hz_loop0.pico");
	}

	public static byte[] sampleStripChartFileContent4() {
		return loadResource("stripchart_110nm_5000Hz_loop10.pico");
	}

	public static byte[] sampleStripChartFileContent5() {
		return loadResource("stripchart/stripchart_breakAway_0_02231727.007.pico");
	}

	public static byte[] sampleStripChartFileContent6() {
		return loadResource("stripchart/stripchart_fetchMolecule_0_02231727.008.pico");
	}
	
	public static byte[] sampleNanoscope5LoseMoleculeStripChart4360NmPerS() {
	  return loadResource("stripchart/nanoscope5_000060_02040339.011_lose");
	}
  
  public static byte[] sampleNanoscope5LoseMoleculeStripChart513NmPerS() {
    return loadResource("stripchart/nanoscope5_000641_02040504.004_lose");
  }
  
  public static byte[] sample2pt5V() {
    return loadResource("2.5V_03121736.007");
  }
  
  public static byte[] sampleStripChartFetch225nmRefolding160nmHover52msBreak435nm2180nmPerS() {
    return loadResource("stripchart/stripchart_Fetch225nm_Refolding160nm_Hover52ms_Break435nm_2180nmPerS.pico");
  }
  
  public static byte[] stripchart_Fetch225nm_Refolding160nm_Hover50ms_Break435nm_2180nmPerS() {
    return loadResource("stripchart/stripchart_Fetch225nm_Refolding160nm_Hover50ms_Break435nm_2180nmPerS_03181825.002.pico");
  }
  
  public static byte[] stripchart_Fetch275nm_Refolding210nm_RefoldingApproachVelocity2186nmPerS_Hover50ms_Break435nm_Velocity2180nmPerS() {
    return loadResource("stripchart/Fetch275nm_Refolding210nm_RefoldingApproachVelocity2186nmPerS_Hover50ms_Break435nm_Velocity2180nmPerS_03221701.002.pico");
  }
  
  public static byte[] shorterDeflectionStripchart() {
    return loadResource("stripchart/shorter_deflection_03220135.016.pico");
  }

  public static byte[] sampleThreeRefolding000447() {
    return loadResource("stripchart/000447_05061541.003_refold_false_30.0_82.99999999999999.pico");
  }
}
